/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdBusinessScenariosBo;
import com.comac.ins.isfd.domain.bo.query.IsfdBusinessScenariosQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdBusinessScenariosVo;
import com.comac.ins.isfd.service.IIsfdBusinessScenariosService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 业务场景-系统
 *
 * @author hxloongs
 * @date 2025-02-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/business/scenarios")
public class IsfdBusinessScenariosController extends BaseController {

    @Autowired
    private IIsfdBusinessScenariosService isfdBusinessScenariosService;

    /**
     * 左侧树
     */
    @SaCheckPermission("isfd:businessScenarios:list")
    @GetMapping("/tree")
    public List<IsfdBusinessScenariosVo> tree(@RequestParam(value = "name", required = false) String name) {
        return isfdBusinessScenariosService.tree(name);
    }

    /**
     * 查询业务场景-系统列表
     */
    @SaCheckPermission("isfd:businessScenarios:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdBusinessScenariosVo> list(@RequestBody IsfdBusinessScenariosQueryBo queryBo) {
        return isfdBusinessScenariosService.queryPageList(queryBo);
    }

    /**
     * 获取业务场景-系统详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:businessScenarios:query")
    @GetMapping("/detail")
    public R<IsfdBusinessScenariosVo> detail(@RequestParam("id") Long id) {
        return R.ok(isfdBusinessScenariosService.queryById(id));
    }

    /**
     * 新增业务场景-系统
     */
    @SaCheckPermission("isfd:businessScenarios:add")
    @Log(title = "业务场景/系统", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IsfdBusinessScenariosBo bo) {
        return toAjax(isfdBusinessScenariosService.insertByBo(bo));
    }

    /**
     * 修改业务场景-系统
     */
    @SaCheckPermission("isfd:businessScenarios:update")
    @Log(title = "业务场景/系统", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/update")
    public R<Void> update(@Validated(EditGroup.class) @RequestBody IsfdBusinessScenariosBo bo) {
        return toAjax(isfdBusinessScenariosService.updateByBo(bo));
    }

    /**
     * 删除业务场景-系统
     *
     * @param id 主键串
     */
    @SaCheckPermission("isfd:businessScenarios:remove")
    @Log(title = "业务场景/系统", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@NotNull(message = "主键不能为空")
                          @PathVariable Long id) {
        return toAjax(isfdBusinessScenariosService.deleteWithValidById(id));
    }
}
